package com.example.cwproject.mapper;

import com.example.cwproject.entity.Post;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface PostMapper {

    @Insert("insert into `post` (userID,text,title,road,duration,postTime) values (#{userID},#{text},#{title},#{road},#{duration},#{time})")
    void insert(Integer userID, String text, String title, String road, Long duration,String time);

    @Select("select postID from post where userID = #{userID} and postTime = #{time}")
    Integer selectPostID(Integer userID, String time);

    @Delete("delete from `post` where postID=#{postID}")
    void delete(Integer postID);

    @Select("select `post`.*, `user`.userName, `user`.avatar from `post`,`user`  where `post`.userID=`user`.userID order by `user`.userName")
    List<Post> selectAllPost();

    @Select(("select `post`.* ,`user`.userName, `user`.avatar from `post` , `user` where `user`.userName=#{userName} and `user`.userID=`post`.userID"))
    List<Post> selectByUser(String userName);

    @Select("select picture_road from `picture` where `picture`.PostID = #{postID}")
    String findPictureImage(Integer postID);

    @Select("select `post`.* ,`user`.userName, `user`.avatar from `post` , `user` where `user`.email=#{email} and `user`.userID=`post`.userID")
    List<Post> selectByEmail(String email);
}
